package com.demomaster.quickcompat.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.EditText;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatEditText;

import com.demomaster.quickcompat.R;
import com.demomaster.quickcompat.widget.base.QuickViewImpl;
import com.demomaster.quickcompat.widget.base.QuickViewUtil;

public class QuickEditView extends AppCompatEditText {

    public QuickEditView(@NonNull Context context) {
        super(context);
        init(context, null, R.attr.QuickEditView);
    }

    public QuickEditView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context, null, R.attr.QuickEditView);
    }

    public QuickEditView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, null, R.attr.QuickEditView);
    }

    QuickViewImpl quickViewImpl;
    private void init(Context context, AttributeSet attrs, int defStyleAttr) {
        quickViewImpl = new QuickViewImpl(this, attrs, defStyleAttr);
        //if (quickViewAttribute.backgroundDrawable != null||quickViewAttribute.borderWidth != 0||quickViewAttribute.borderColor != null) {
        //如果要设置莫项为false，在前面加负号 ，比如android.R.attr.state_focesed标志true，-android.R.attr.state_focesed就标志false
        // QDRoundRectDrawable bg_normal = QDRoundRectDrawable.fromAttributeSet(context, attrs, defStyleAttr);
//            Drawable bg_selected = QDRoundRectDrawable.fromAttributeSetByState(context, attrs, defStyleAttr,android.R.attr.state_selected);
//            Drawable bg_checked = QDRoundRectDrawable.fromAttributeSetByState(context, attrs, defStyleAttr,android.R.attr.state_checked);
//            QDRoundRectDrawable bg_enabled = QDRoundRectDrawable.fromAttributeSetByState(context, attrs, defStyleAttr,android.R.attr.state_enabled);
//
//            //TODO 处理 描边颜色
//            StateListDrawable drawable = new StateListDrawable();
//            drawable.addState(new int[]{android.R.attr.state_focused}, bg_normal);
//            drawable.addState(new int[]{android.R.attr.state_pressed}, bg_normal);
//            drawable.addState(new int[]{android.R.attr.state_selected}, bg_selected);
//            drawable.addState(new int[]{android.R.attr.state_checked}, bg_checked);
//            drawable.addState(new int[]{-android.R.attr.state_enabled}, bg_enabled);
//            drawable.addState(new int[]{}, bg_normal);//默认
        if (quickViewImpl.attribute.backgroundDrawable != null) {
            //colorBg = QuickViewUtil.getStateColorsFromDrawable(quickViewImpl.attribute.backgroundDrawable);
            //Drawable drawable2 = QuickDrawableUtil.convertToRadiusDrawable(quickViewImpl.attribute.backgroundDrawable, quickViewImpl.attribute.radius);
            QuickViewUtil.setBackgroundKeepingPadding(this,quickViewImpl.attribute.backgroundDrawable);
        }

        //fromAttributeSet(context, attrs, defStyleAttr);
        //}
    }

}
